package com.saint.easemobui.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMMessage;
import com.saint.easemobui.R;
import com.saint.easemobui.easeui.ui.EaseChatFragment;
import com.saint.easemobui.easeui.widget.chatrow.EaseCustomChatRowProvider;


public class ChatActivity extends AppCompatActivity {
    private EaseChatFragment chatFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat);

        // 这里直接使用EaseUI封装好的聊天界面
        chatFragment = new EaseChatFragment();
        // 将参数传递给聊天界面
        chatFragment.setArguments(getIntent().getExtras());
        chatFragment.setChatFragmentHelper(new EaseChatFragment.EaseChatFragmentHelper() {
            @Override
            public void onSetMessageAttributes(EMMessage message) {
                message.setAttribute("my_logo", "http://img5.imgtn.bdimg.com/it/u=547138142,3998729701&fm=27&gp=0.jpg");
//                message.setAttribute("avatar","http://img5.imgtn.bdimg.com/it/u=1215764257,2244678340&fm=27&gp=0.jpg" );
                message.setAttribute("avatar","http://img5.imgtn.bdimg.com/it/u=547138142,3998729701&fm=27&gp=0.jpg");
//                message.setAttribute("my_logo","http://img5.imgtn.bdimg.com/it/u=1215764257,2244678340&fm=27&gp=0.jpg" );

                message.setAttribute("nick", "小白");
            }

            @Override
            public void onEnterToChatDetails() {

            }

            @Override
            public void onAvatarClick(String username) {

            }

            @Override
            public void onAvatarLongClick(String username) {

            }

            @Override
            public boolean onMessageBubbleClick(EMMessage message) {
                return false;
            }

            @Override
            public void onMessageBubbleLongClick(EMMessage message) {

            }

            @Override
            public boolean onExtendMenuItemClick(int itemId, View view) {
                return false;
            }

            @Override
            public EaseCustomChatRowProvider onSetCustomChatRowProvider() {
                return null;
            }
        });

//                message.setAttribute("from_headportrait", "http://img5.imgtn.bdimg.com/it/u=547138142,3998729701&fm=27&gp=0.jpg");
//                message.setAttribute("to_headportrait", "http://img5.imgtn.bdimg.com/it/u=1215764257,2244678340&fm=27&gp=0.jpg");

//        EMClient.getInstance().getCurrentUser().

        getSupportFragmentManager().beginTransaction().add(R.id.ec_layout_container, chatFragment).commit();
    }
}
